#! /usr/bin/python
# -*- coding:  utf-8 -*-
#
# accoufer : cgi script for creating databases
# 
# Copyright S.Keim 2011
# Available under the MIT licence see the COPYING file


import accoufer
import shelve
import cgi 
import os

def run():
    if os.path.exists(accoufer.USER_PATH):
        return error("Already installed")

    try:
        os.mkdir(accoufer.DATA_PATH)
    except:
        pass # file exist
    shelve.open(accoufer.USER_PATH, 'c')
    shelve.open(accoufer.EMAIL_PATH, 'c')
    clients = shelve.open(accoufer.CLIENT_PATH, 'c')
    clients[accoufer.COUNT_KEY] = 0

    msg =  SUCCES
    print accoufer.HTML%("Site installed", msg )

  

def error(txt):
    msg = ERROR%txt
    print accoufer.HTML%("Error", msg)


SUCCES = """<h1>Site installed</h1>Successful install.<p/><hr/> <a href="./index.html">Start</a>"""


ERROR = "<h1>Install error</h1><b>%s</b>"

if __name__=="__main__":
    run()

